﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;

namespace ScormModel
{
    [Serializable()]
    public class RuleConditions
    {
        private string _conditionCombination;
        private List<RuleCondition> _listRuleCondition;
         [NonSerialized]
        private XmlNode _ruleConditionsContent;
        [XmlAttribute("conditionCombination")]
        public string ConditionCombination
        {
            get { return this._conditionCombination; }
            set { this._conditionCombination = value; }
        }
        [XmlElement("ruleCondition", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public List<RuleCondition> ListRuleCondition
        {
            get { return this._listRuleCondition; }
            set { this._listRuleCondition = value; }
        }
        
        [XmlIgnoreAttribute]
        public XmlNode RuleConditionsContent
        {
            get { return this._ruleConditionsContent; }
            set { this._ruleConditionsContent = value; }
        }
        public void buildRuleConditions()
        {
            _listRuleCondition = new List<RuleCondition>();
            XmlAttributeCollection attList = _ruleConditionsContent.Attributes;
            for (int i = 0; i < attList.Count; i++)
            {
                if (attList[i].Name == "combination")
                {
                    _conditionCombination = attList[i].Value;
                }
            }    
            for (int i = 0; i < _ruleConditionsContent.ChildNodes.Count; i++)
            {
                RuleCondition ruleCondition = new RuleCondition();
                ruleCondition.RuleConditionContent = _ruleConditionsContent.ChildNodes[i];
                ruleCondition.buildRuleCondition();
                _listRuleCondition.Add(ruleCondition);
            }
        }
    }
}
